package com.company;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Card{
    private String suit;//牌的花色
    private int rank;//牌的大小

    public Card(String suit, int rank) {
        this.suit = suit;
        this.rank = rank;
    }

    @Override
    public String toString() {
        return "花色："+suit+"牌面"+rank;
    }
}
public class CardDemo {
    private static final String[] suits=new String[]{"♣","♦","♥","♠"};
    public static List<Card> buyCard(){
        List<Card> cards=new ArrayList<>();
        for(int i=0;i<4;++i){
            for(int j=0;j<13;++j){
                Card card=new Card(suits[i],j);
               cards.add(card);
            }
        }
        return cards;
    }
    public static void shuffle(List<Card> cards){
        Random random=new Random();
        for (int i = cards.size()-1; i > 0; i--) {
            int index= random.nextInt(i);
            Card tmp=cards.get(i);
            //Card tmp=cards[i]
            cards.set(i,cards.get(index));
            //cards[i]=cards[index];
            cards.set(index,tmp);
            //cards[index]=tmp;
        }
    }

    public static void main(String[] args) {
        List<Card> cards=buyCard();
        System.out.println("买牌：");
        System.out.println(cards);//买牌
        shuffle(cards);
        System.out.println("洗牌");
        System.out.println(cards);

        List<List<Card>> hands=new ArrayList<>();

        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();
        List<Card> hand3=new ArrayList<>();

        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);
        //每个人轮流揭牌，共揭五轮
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card=cards.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第一个人手里的牌："+hand1);
        System.out.println("第二个人手里的牌："+hand2);
        System.out.println("第三个人手里的牌："+hand3);
    }
}
